package org.soaring.panel;

import java.awt.*;
import java.math.BigDecimal;
import java.math.RoundingMode;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import com.tool.tcpimg.ChatBox;
import org.come.bean.ImgZoom;
import org.come.until.AnalysisString;
import org.come.until.CutButtonImage;
import org.come.until.FormsManagement;
import org.soaring.btn.SoaringBtn;

import com.tool.btn.FormsOnOffBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



public class SoaringPanel extends JPanel {

    // 转换按钮 ， 升级 ， 兑换
    private SoaringBtn transformation, upgrade, exchange;

    // 经验条 ， 经验值 ，拥有修为点， 人物等级，升级所需修为点 ， 属性点 ，兑换所需修为点
    private JLabel strip, experience, havePoint, level, upPoint, convertibilityPoints, exchangePoint;

    public SoaringPanel() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
    		this.setPreferredSize(new Dimension(332, 407));
            this.setOpaque(false);
            this.setLayout(null);

            // 关闭按钮事件
            FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 81);
            offBtn.setBounds(332 - 37, 10, 25, 25);
            this.add(offBtn);

            transformation = new SoaringBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_BLACK, "转换", 1, this);
            upgrade = new SoaringBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_BLACK, "升级", 2, this);
            exchange = new SoaringBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_BLACK, "兑换", 3, this);
            strip = new JLabel();
            experience = new JLabel("123132132");
            havePoint = new JLabel("2/30");
            level = new JLabel("150级");
            upPoint = new JLabel("6");
            convertibilityPoints = new JLabel("10/40");
            exchangePoint = new JLabel("10");

            Font f = new Font("宋体", Font.PLAIN, 15);

            transformation.setBorder(null);
            upgrade.setBorder(null);
            exchange.setBorder(null);

            transformation.setOpaque(false);
            upgrade.setOpaque(false);
            exchange.setOpaque(false);
            strip.setOpaque(false);
            havePoint.setOpaque(false);
            level.setOpaque(false);
            upPoint.setOpaque(false);
            convertibilityPoints.setOpaque(false);
            exchangePoint.setOpaque(false);

            transformation.setBackground(null);

            strip.setIcon(new ImageIcon("inkImg/hongmu/soaring/经验w152,h13px.png"));

            experience.setHorizontalAlignment(SwingConstants.CENTER);
            
            experience.setForeground(Color.white);
            experience.setFont(f);
            havePoint.setForeground(Color.white);
            havePoint.setFont(f);
            level.setForeground(Color.white);
            level.setFont(f);
            upPoint.setForeground(Color.white);
            upPoint.setFont(f);
            exchangePoint.setForeground(Color.white);
            exchangePoint.setFont(f);
            convertibilityPoints.setForeground(Color.white);
            convertibilityPoints.setFont(f);

            transformation.setBounds(205 + 25, 80 - 14, 59, 24);
            upgrade.setBounds(125 + 25, 200 - 14, 59, 24);
            exchange.setBounds(125 + 25, 330 + 6, 59, 24);
            strip.setBounds(109 + 25, 46 - 13, 152, 23);
            experience.setBounds(109 + 25, 46 - 14, 152, 19);
            havePoint.setBounds(123 + 25, 80 - 14, 70, 19);
            level.setBounds(170 + 25, 145 - 14, 80, 19);
            upPoint.setBounds(170 + 25, 169 - 14, 80, 19);
            convertibilityPoints.setBounds(186 + 22, 276 + 6, 50, 19);
            exchangePoint.setBounds(186 + 22, 300 + 8, 50, 19);

            this.add(transformation);
            this.add(upgrade);
            this.add(exchange);
            this.add(experience);
            this.add(strip);
            this.add(havePoint);
            this.add(level);
            this.add(upPoint);
            this.add(convertibilityPoints);
            this.add(exchangePoint);
        } else {
            //
    		this.setPreferredSize(new Dimension(302, 405));
    		this.setOpaque(false);
    		this.setLayout(null);

    		// 关闭按钮事件
    		FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/hongmu/s74.png", 1, 81);
    		offBtn.setBounds(282, 0, 25, 25);
    		this.add(offBtn);

    		transformation = new SoaringBtn("img/soaring/转化w60,h78px.png", 1, UIUtils.COLOR_BTNPUTONG, "", 1, this);
    		upgrade = new SoaringBtn("img/soaring/升级w60,h78px.png", 1, UIUtils.COLOR_BTNPUTONG, "", 2, this);
    		exchange = new SoaringBtn("img/soaring/兑换w60,h78px.png", 1, UIUtils.COLOR_BTNPUTONG, "", 3, this);
    		strip = new JLabel();
    		experience = new JLabel("123132132");
    		havePoint = new JLabel("2/30");
    		level = new JLabel("150级");
    		upPoint = new JLabel("6");
    		convertibilityPoints = new JLabel("10/40");
    		exchangePoint = new JLabel("10");

    		Font f = new Font("宋体", Font.PLAIN, 15);

    		transformation.setBorder(null);
    		upgrade.setBorder(null);
    		exchange.setBorder(null);

    		transformation.setOpaque(false);
    		upgrade.setOpaque(false);
    		exchange.setOpaque(false);
    		strip.setOpaque(false);
    		havePoint.setOpaque(false);
    		level.setOpaque(false);
    		upPoint.setOpaque(false);
    		convertibilityPoints.setOpaque(false);
    		exchangePoint.setOpaque(false);

    		transformation.setBackground(null);

    		strip.setIcon(new ImageIcon("img/soaring/经验w152,h13px.png"));

    		experience.setHorizontalAlignment(SwingConstants.CENTER);

    		experience.setForeground(Color.white);
    		experience.setFont(f);
    		havePoint.setForeground(Color.white);
    		havePoint.setFont(f);
    		level.setForeground(Color.white);
    		level.setFont(f);
    		upPoint.setForeground(Color.white);
    		upPoint.setFont(f);
    		exchangePoint.setForeground(Color.white);
    		exchangePoint.setFont(f);
    		convertibilityPoints.setForeground(Color.white);
    		convertibilityPoints.setFont(f);

    		this.transformation.setBounds(205, 80, 60, 26);
    		this.upgrade.setBounds(125, 200, 60, 26);
    		this.exchange.setBounds(125, 330, 60, 26);
    		this.strip.setBounds(109, 46, 152, 19);
    		this.experience.setBounds(109, 46, 152, 19);
    		this.havePoint.setBounds(123, 80, 70, 19);
    		this.level.setBounds(170, 145, 80, 19);
    		this.upPoint.setBounds(170, 169, 80, 19);
    		this.convertibilityPoints.setBounds(186, 276, 50, 19);
    		this.exchangePoint.setBounds(186, 300, 50, 19);

    		this.add(transformation);
    		this.add(upgrade);
    		this.add(exchange);
    		this.add(experience);
    		this.add(strip);
    		this.add(havePoint);
    		this.add(level);
    		this.add(upPoint);
    		this.add(convertibilityPoints);
    		this.add(exchangePoint);
        }

    }

    // 满经验值
    private BigDecimal maxExprience = new BigDecimal("10000000000");

    /**
     * 经验条变动
     *
     * @param decimal
     */
    public void setWieth(BigDecimal decimal) {
        // 得出倍率
        BigDecimal divide = decimal.divide(maxExprience, 2, RoundingMode.HALF_DOWN);
        // 换算为宽度
        BigDecimal multiply = divide.multiply(new BigDecimal("152"));
        if (divide.compareTo(new BigDecimal(0)) <= 0) {
            this.getStrip().setSize(1, 19);
        } else if (divide.compareTo(new BigDecimal(1)) <= 0) {
            this.getStrip().setSize(multiply.intValue(), 19);
        } else {
            this.getStrip().setSize(152, 19);
        }
    }

    /**
     * 获取数据打开经验转换面板
     *
     * @param level
     *            等级
     * @param experience
     *            经验
     * @param convertibilityPoints
     *            属性点
     * @param havePoint
     *            修为点
     */
    public void SoaringExprience(int level, BigDecimal experience, int convertibilityPoints, int havePoint) {
        // 经验条
        setWieth(experience);

        // 经验值
        SoaringMainFrame.getSoaringMainFrame().getSoaringPanel().getExperience().setText(experience + "");

        // 人物等级
        int lvlint = AnalysisString.lvlint(level);
        SoaringMainFrame.getSoaringMainFrame().getSoaringPanel().getLevel().setText(lvlint + "级");
        int need = 0;
        // 最大拥有修为点
        if (lvlint < 150) {
            lvlint = 30;
            need = 6;
        } else {
            need = lvlint - 144;
            lvlint = (lvlint - 144) * 5;
        }
        // 升级所需点数
        SoaringMainFrame.getSoaringMainFrame().getSoaringPanel().getUpPoint().setText(need + "");
        // 拥有修为点
        SoaringMainFrame.getSoaringMainFrame().getSoaringPanel().getHavePoint().setText(havePoint + "/" + lvlint);

        // 属性点
        SoaringMainFrame.getSoaringMainFrame().getSoaringPanel().getConvertibilityPoints()
                .setText(convertibilityPoints + "/" + 40);

        // 兑换所需修为点
        SoaringMainFrame.getSoaringMainFrame().getSoaringPanel().getExchangePoint()
                .setText((convertibilityPoints + 1) + "");

        FormsManagement.showForm(81);
    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintChildren(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
        	if (icon == null) {
                icon = new ImageIcon("inkImg/old/background/S41.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 332, 407, this);
        } else {
            //
        	if (icon == null) {
        		icon = new ImageIcon("img/soaring/转换经验w307,h407px.png");
        	}
        	g.drawImage(icon.getImage(), -3, 0, 307, 407, this);
        }
    }

    public SoaringBtn getTransformation() {
        return transformation;
    }

    public void setTransformation(SoaringBtn transformation) {
        this.transformation = transformation;
    }

    public SoaringBtn getUpgrade() {
        return upgrade;
    }

    public void setUpgrade(SoaringBtn upgrade) {
        this.upgrade = upgrade;
    }

    public SoaringBtn getExchange() {
        return exchange;
    }

    public void setExchange(SoaringBtn exchange) {
        this.exchange = exchange;
    }

    public JLabel getStrip() {
        return strip;
    }

    public void setStrip(JLabel strip) {
        this.strip = strip;
    }

    public JLabel getExperience() {
        return experience;
    }

    public void setExperience(JLabel experience) {
        this.experience = experience;
    }

    public JLabel getHavePoint() {
        return havePoint;
    }

    public void setHavePoint(JLabel havePoint) {
        this.havePoint = havePoint;
    }

    public JLabel getLevel() {
        return level;
    }

    public void setLevel(JLabel level) {
        this.level = level;
    }

    public JLabel getUpPoint() {
        return upPoint;
    }

    public void setUpPoint(JLabel upPoint) {
        this.upPoint = upPoint;
    }

    public JLabel getConvertibilityPoints() {
        return convertibilityPoints;
    }

    public void setConvertibilityPoints(JLabel convertibilityPoints) {
        this.convertibilityPoints = convertibilityPoints;
    }

    public JLabel getExchangePoint() {
        return exchangePoint;
    }

    public void setExchangePoint(JLabel exchangePoint) {
        this.exchangePoint = exchangePoint;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

}
